"""计划执行"""

from enum import Enum
from typing import Any, Dict, List, Optional
from pydantic import BaseModel


class ExecutionStatus(Enum):
    """计划执行状态."""
    PENDING = "pending"
    RUNNING = "running"
    COMPLETED = "completed"
    FAILED = "failed"
    SKIPPED = "skipped"


class StepResult(BaseModel):
    """单步计划执行结果"""
    step_id: str
    status: ExecutionStatus
    output: Any
    error: Optional[str] = None
    execution_time: float = 0.0
    metadata: Dict[str, Any] = None

    def __post_init__(self):
        if self.metadata is None:
            self.metadata = {}


class ExecutionResult(BaseModel):
    """完整计划的执行结果"""
    plan_id: str
    status: ExecutionStatus
    step_results: List[StepResult]
    total_time: float
    success_rate: float
    final_output: Any
    metadata: Dict[str, Any]